package sto.android.app;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.lhzw.barcodehelper.BarcodeHelper;
/**
 * v1.0
 * @author edb
 *
 */
public class EdbDevJNI implements StoJNI {
	private static String TAG = "EdbDevJNI";
	private Context mContext;
	private BarcodeHelper mBarcode;
	public static boolean m_isPowerOn = false;
    public static boolean m_isScanning = false;
    
	private static EdbDevJNI edbDevJni;

	ScanCallBack mScanCB;

	private EdbDevJNI(Context context) {
		this.mContext = context;
	}

	public static EdbDevJNI getInstance(Context context) {
		if (edbDevJni == null) {
			edbDevJni = new EdbDevJNI(context);
		}

		return edbDevJni;
	}

	@Override
	public void SetScannerOn() {
		mBarcode = BarcodeHelper.getBarcodeHelper();
		if(mBarcode != null ){
			m_isPowerOn = true;
		}
	}

	@Override
	public void SetScannerStart() {
		if (mBarcode != null) {
			mBarcode.startScan();
			mBarcode.setScanMode(3);
			m_isScanning = true;
			mBarcode.setScanCallback(new BarcodeHelper.ScanCallback() {

				@Override
				public void onScanResult(byte[] data) {
					if (data != null && !data.equals("")) { // 假如字节数组的不为空，且对象不为null
						String result = new String(data);// 将字节数据转换为字符串
						if (mScanCB != null) {
							mScanCB.onScanResults(result);
						}

					}

				}

			});// 扫码回调函数

		} else {
			SetScannerOn();
			mBarcode.startScan();
			mBarcode.setScanMode(3);
			m_isScanning = true;
			mBarcode.setScanCallback(new BarcodeHelper.ScanCallback() {

				@Override
				public void onScanResult(byte[] data) {
					if (data != null && !data.equals("")) { // 假如字节数组的不为空，且对象不为null
						String result = new String(data);// 将字节数据转换为字符串
						if (mScanCB != null) {
							mScanCB.onScanResults(result);
						}

					}

				}

			});// 扫码回调函数
		}

	}

	@Override
	public void SetScannerStop() {
		if (mBarcode != null) {
			mBarcode.setScanMode(0);
			mBarcode.stopScan();
			m_isScanning = false;
		}

	}

	@Override
	public void SetScannerOff() {
		if (mBarcode != null) {
			mBarcode.setScanMode(0);
			mBarcode.stopScan();
			mBarcode.release();
			mBarcode = null;
			
	        m_isPowerOn = false;
	        m_isScanning = false;
		}

	}

	@Override
	public int SetScannerPara(int para, int value) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int GetScannerPara(int para) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String SetScannerPara(String para, String value) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String GetScannerPara(String para) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void SetScannerRetriger() {
		// TODO Auto-generated method stub

	}

	@Override
	public void SetScannerTimerOut(int sec) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean GetScannerIsScanning() {
		// TODO Auto-generated method stub
		return m_isScanning;
	}

	@Override
	public void SetSystemReboot() {
		// TODO Auto-generated method stub

	}

	@Override
	public void SetSystemShutdown() {
		// TODO Auto-generated method stub

	}

	@Override
	public void SetSystemTime(String mm) {
		// TODO Auto-generated method stub

	}

	@Override
	public void SetMachineCode(String code) {
		// TODO Auto-generated method stub
	}

	@Override
	public String GetMachineCode() {
		TelephonyManager tm = (TelephonyManager) mContext
				.getSystemService(Context.TELEPHONY_SERVICE);

		return tm.getDeviceId();
	}

	@Override
	public void disableKeypad() {
		// TODO Auto-generated method stub

	}

	@Override
	public void disableKeypadEnableCustom(String customstr) {
		// TODO Auto-generated method stub

	}

	@Override
	public void enableKeypad() {
		// TODO Auto-generated method stub

	}

	@Override
	public void enableKeydownTone() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusKeydownTone() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void disableKeydownTone() {
		// TODO Auto-generated method stub

	}

	@Override
	public void TurnOffStatusBarExpand() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusBarExpand() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void TurnOnStatusBarExpand() {
		// TODO Auto-generated method stub

	}

	@Override
	public void TurnOffUSBDebug() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusUSBDebug() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void TurnOnUSBDebug() {
		// TODO Auto-generated method stub

	}

	@Override
	public void TurnOffInstallManager() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusInstallManager() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void TurnOnInstallManager() {
		// TODO Auto-generated method stub

	}

	@Override
	public void TurnOnScreenLock() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusScreenLock() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void TurnOffScreenLock() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusWakeUp() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void CfgPowerKeyWakeUp() {
		// TODO Auto-generated method stub

	}

	@Override
	public void CfgAnyKeyWakeUp() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Disable_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Enable_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusTouch_screen() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void StoJNI_InstallApkWithSilence(String apkPath,
			boolean runAfterFinished) {
		// TODO Auto-generated method stub

	}

	@Override
	public void TurnOnOffGPS(boolean set) {
		// TODO Auto-generated method stub

	}

	@Override
	public void TurnOnOffBrowser(boolean set) {
		// TODO Auto-generated method stub

	}

	@Override
	public void Disable_home_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Enable_home_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusTouch_Home_screen() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void Disable_menu_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Enable_menu_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusTouch_Menu_screen() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void Disable_back_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Enable_back_touch_screen() {
		// TODO Auto-generated method stub

	}

	@Override
	public int GetStatusTouch_Back_screen() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getPlatform() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getJniVer() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getEventFuction(int keycode) {
		Log.d(TAG, "######" + TAG + "getEventFunction keycode= " + keycode);
        switch(keycode) {
        case 19:
            return 19;
        case 20:
            return 20;
        case 21:
            return 21;
        case 22:
            return 22;
        case 24:
            return 24;
        case 25:
            return 25;
        case 66:
            return 66;
        case 67:
            return 67;
        case 82:
            return 82;
        case 119:
            return 131;
        case 249:
            return 110;
        
        default:
            return keycode;
        }
	}

	public String getPdaBrand() {
		return "Engine";
	}

	@Override
	public void setmScanCB(ScanCallBack scanCallBack) {

		this.mScanCB = scanCallBack;
	}

	@Override
	public void SetGPIOStatusJNI(int var1, int var2) {
		// TODO Auto-generated method stub

	}

	@Override
	public int getmScanModel() {
		// TODO Auto-generated method stub
		return 0;
	}
}
